﻿using System;
using System.Runtime.InteropServices;
using Utils.ShellExtension.ContextMenu;

namespace org.syncsoft.overalt.gui.contextMenu
{

    [ComVisible(true), Guid("ead5004b-29e0-4537-9186-6e9a75389b37")]
    public class ContextMenu : BaseContextMenu
    {
        [ComRegisterFunction]
        public static void RegisterFunction(Type t)
        {
            //Register for files
            RegisterContextMenu.Register("*", t.GUID);
            //Register for folders
            RegisterContextMenu.Register("Directory", t.GUID);
            //Register for drives
            RegisterContextMenu.Register("Drive", t.GUID);
        }

        [ComUnregisterFunction]
        public static void UnregisterFunction(Type t)
        {
            RegisterContextMenu.Unregister("*", t.GUID);
            RegisterContextMenu.Unregister("Directory", t.GUID);
            RegisterContextMenu.Unregister("Drive", t.GUID);
        }

        public override void AssembleMenu()
        {
            System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(@"C:\Arquivos de programas\Overalt\img\001.png");
            System.Drawing.Bitmap bmp1 = new System.Drawing.Bitmap(@"C:\Arquivos de programas\Overalt\img\002.png");
            System.Drawing.Bitmap bmp2 = new System.Drawing.Bitmap(@"C:\Arquivos de programas\Overalt\img\003.png");
            System.Drawing.Bitmap bmp3 = new System.Drawing.Bitmap(@"C:\Arquivos de programas\Overalt\img\004.png");
            System.Drawing.Bitmap bmp4 = new System.Drawing.Bitmap(@"C:\Arquivos de programas\Overalt\img\005.png");
            System.Drawing.Bitmap bmp5 = new System.Drawing.Bitmap(@"C:\Arquivos de programas\Overalt\img\006.png");
            System.Drawing.Bitmap bmp6 = new System.Drawing.Bitmap(@"C:\Arquivos de programas\Overalt\img\007.png");
            System.Drawing.Bitmap bmp7 = new System.Drawing.Bitmap(@"C:\Arquivos de programas\Overalt\img\008.png");
            System.Drawing.Bitmap bmp8 = new System.Drawing.Bitmap(@"C:\Arquivos de programas\Overalt\img\009.png");
            System.Drawing.Bitmap bmp9 = new System.Drawing.Bitmap(@"C:\Arquivos de programas\Overalt\img\010.png");
            MenuItems menuItems1 = new MenuItems("Overalt", 0, false, bmp, false);
            MenuItems menuItems2 = new MenuItems("Criar Repositório", 1, false, bmp1, true);
            MenuItems menuItems3 = new MenuItems("Configurações", 2, false, bmp2, false);
            MenuItems menuItems4 = new MenuItems("Checar Modificações", 3, false, bmp3, false);
            MenuItems menuItems5 = new MenuItems("Baixar", 4, false, bmp4, false);
            MenuItems menuItems6 = new MenuItems("Enviar", 5, false, bmp5, false);
            MenuItems menuItems7 = new MenuItems("Propriedades", 6, false, bmp6, false);
            MenuItems menuItems8 = new MenuItems("Compartilhar Arquivo", 7, false, bmp7, false);
            MenuItems menuItems9 = new MenuItems("Visualizar Histórico", 8, false, bmp9, false);
            MenuItems menuItems10 = new MenuItems("Sobre", 9, false, bmp8, true);
            menuItems2.Click += new Utils.ShellExtension.ContextMenu.MenuItems.MenuClickHandler(menuItems2_Click);
            menuItems3.Click += new Utils.ShellExtension.ContextMenu.MenuItems.MenuClickHandler(menuItems3_Click);
            menuItems4.Click += new Utils.ShellExtension.ContextMenu.MenuItems.MenuClickHandler(menuItems4_Click);
            menuItems5.Click += new Utils.ShellExtension.ContextMenu.MenuItems.MenuClickHandler(menuItems5_Click);
            menuItems6.Click += new Utils.ShellExtension.ContextMenu.MenuItems.MenuClickHandler(menuItems6_Click);
            menuItems7.Click += new Utils.ShellExtension.ContextMenu.MenuItems.MenuClickHandler(menuItems7_Click);
            menuItems8.Click += new Utils.ShellExtension.ContextMenu.MenuItems.MenuClickHandler(menuItems8_Click);
            menuItems9.Click += new Utils.ShellExtension.ContextMenu.MenuItems.MenuClickHandler(menuItems9_Click);
            menuItems10.Click += new Utils.ShellExtension.ContextMenu.MenuItems.MenuClickHandler(menuItems10_Click);
            //This order is important. Always insert the parent container and then the child!
            InsertMenu(menuItems1);
            AddMenu(menuItems1, menuItems2);
            AddMenu(menuItems1, menuItems3);
            AddMenu(menuItems1, menuItems4);
            AddMenu(menuItems1, menuItems5);
            AddMenu(menuItems1, menuItems6);
            AddMenu(menuItems1, menuItems7);
            AddMenu(menuItems1, menuItems8);
            AddMenu(menuItems1, menuItems9);
            AddMenu(menuItems1, menuItems10);
        }

        private void menuItems2_Click()
        {
            Socket socket = new Socket();
            socket.Send(1, Directory, null);
        }

        private void menuItems3_Click()
        {
            Socket socket = new Socket();
            socket.Send(2, Directory, null);
        }

        private void menuItems4_Click()
        {
            Socket socket = new Socket();
            socket.Send(3, Directory, null);
        }

        private void menuItems5_Click()
        {
            Socket socket = new Socket();
            socket.Send(4, Directory, null);
        }

        private void menuItems6_Click()
        {
            Socket socket = new Socket();
            socket.Send(5, Directory, null);
        }

        private void menuItems7_Click()
        {
            Socket socket = new Socket();
            socket.Send(6, Directory, null);
        }

        private void menuItems8_Click()
        {
            Socket socket = new Socket();
            socket.Send(7, Directory, null);
        }

        private void menuItems9_Click()
        {
            Socket socket = new Socket();
            socket.Send(8, Directory, null);
        }

        private void menuItems10_Click()
        {
            Socket socket = new Socket();
            socket.Send(9, Directory, null);
        }
    }
}
